<?php
/**
 *      [Elitechmedia!] (C)2001-2099 MYSELF Inc.
 *      This is NOT a freeware, use is subject to license terms
 *
 *      $Id: adduserment.php 22609 2013-10-16 01:55:33Z zhangchaofeng
 */
if(!isset($_SESSION)){
	session_start();
}
if(!$_SESSION['uid']){
	require_once "tmp/login.htm";exit;
}
include_once("classes/DB.class.php");
include_once("classes/page.class.php");
include_once("function/member.php");
include_once("function/util.func.php");
date_default_timezone_set('Asia/Shanghai');
$uid=addslashes($_REQUEST['uid']);
$url="userment.php";
if($uid!=''):
$info = $GLOBALS["DB"]->result("SELECT * FROM user where uid='$uid'");
$info=$info[0];
endif;
if($_SERVER['REQUEST_METHOD'] == 'POST'):
	$data['username']=addslashes($_POST['username']);
	$upid=$_POST['upid'];
	if($data['username']!=''):
		$data['password']=md5($_POST['password']);
		$data['c_id']=addslashes($_POST['c_id']);
		if($upid!=''):
			$GLOBALS["DB"]->execute_event("update user set ".implode_field_value($data) ." where uid='$upid'");
			$message="<font color='green'>您的操作已经成功....</font>";
			$text="如果您的浏览器没有自动跳转，请点击这里";
			include 'tmp/success.htm';exit;
		else:
			$username=$data['username'];
			$uid = $GLOBALS["DB"]->result("SELECT uid FROM user where username='$username'");
			$newuid=$uid[0]['uid'];
			$data['createdate']=date('Y-m-d',time());
			if($newuid):
				$message="<font color='red'>对不起该用户已经存在,用户名不可以重复...!</font>";
				$text="如果您的浏览器没有自动跳转，请点击这里";
				include 'tmp/error.htm';exit;
			else:
				$fid = $GLOBALS["DB"]->execute_event("INSERT INTO user set ".implode_field_value($data));
				if(!$fid):
					$message="<font color='red'>对不起数据保存失败.!!</font>";
					$text="如果您的浏览器没有自动跳转，请点击这里";
					include 'tmp/error.htm';exit;
				else:
					$message="<font color='green'>您的操作已经成功....</font>";
					$text="如果您的浏览器没有自动跳转，请点击这里";
					include 'tmp/success.htm';exit;
				endif;
			endif;
		endif;
	else:
		$message="<font color='red'>用户名不能为空...!!</font>";
		$text="如果您的浏览器没有自动跳转，请点击这里";
		include 'tmp/error.htm';exit;
	endif;
endif;
$data_row = $GLOBALS["DB"]->result("SELECT id,c_name FROM company where 1=1 ORDER BY id DESC ");
include 'tmp/adduserment.htm';